<template>
 <el-form  Slabel-width="80px">
                <el-form-item label="学号">
                  <el-col :span="15">
                    <el-input v-model="number"></el-input>
                  </el-col>
                </el-form-item>
                <el-form-item label="姓名">
                  <el-col :span="15">
                    <el-input v-model="name"></el-input>
                  </el-col>
                </el-form-item>
                <el-form-item label="所在班级">
                  <el-col :span="15">
                    <el-input v-model="nowclass"></el-input>
                  </el-col>
                </el-form-item>
                <el-form-item label="退学理由">
                  <el-col :span="15">
                    <el-input v-model="reason"></el-input>
                  </el-col>
                </el-form-item><br />
                <el-button type="primary" size="medium" @click="changeStuClass()"
                plain>确认
          </el-button>
              </el-form>
</template>
<script>
import axios from "axios";
import commons from "../../../assets/commons";
export default {
  data(){
    return{
        name:this.$route.params.name,
        number:this.$route.params.number,
        nowclass:'',
        nowclass_id:0,
        aimclass:[],
        aimclass_id:1,
        reason:'',
    }
  },
  methods:{
     changeStuClass(){
       if(this.nowclass_id == this.aimclass_id){
          this.$message({
              type: "error",
              message:'已在目标班级，请重新选择'
              });    
       }else{
      this.$confirm('即将进行转班操作, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          axios.get(commons.baseUrl+"student_account_management/changeStuClass?"+
          "&number=" + this.number +
          "&nc_id=" + this.nowclass_id +
          "&ac_id=" + this.aimclass_id +
          "&reason=" + this.reason).then(res => {
            if (res.data.code == 200) {
              this.$message({
              type: "success",
              message:res.data.message
              });    
              this.$router.push('/headteacher/student_account_management/student_account_query')
            }
           if (res.data.code == 201) {
              this.$message({
              type: "info",
              message:res.data.message
              });    
            }
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消操作'
          });          
        });
      }
    },
    searchClassByC_id(c_id){
        axios.get(
          commons.baseUrl +
            "student_account_management/searchClassByC_id?c_id=" +
            c_id
        ).then(res => { 
          this.nowclass_id=res.data.data.id
          this.nowclass=res.data.data.cname;
        });
    },
  },
  mounted() {
    this.searchClassByC_id( this.$route.params.c_id);
  },
};
</script>
<style scoped></style>
